<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>

    function Parent(msg){
        this.msg = msg;
        this.show = function(){
            console.log(this.msg)
        }
    }
    Parent.prototype.init = function(){
        console.log("这是init", this.msg);
    }

    function Child(msg){}

    // 注意深浅拷贝
    // Child.prototype = Parent.prototype;
    // for(let i in Parent.prototype){
    //     Child.prototype[i] = Parent.prototype[i];
    // }
    Child.prototype = {
        ...Parent.prototype
    }
    // Child.prototype.init = function(){
    //     console.log("这是改写之后的init")
    // }

    const p = new Parent("hello");
    console.log(p);
    p.init();
    p.show();

    const c = new Child("world");
    console.log(c);
    c.init();
    c.show();

    

    
</script>
</html>